package com.ytjj.qmyx.supplychain.api.controller;

import com.ytjj.qmyx.supplychain.common.api.CommonPage;
import com.ytjj.qmyx.supplychain.common.api.CommonResult;
import com.ytjj.qmyx.supplychain.common.model.request.FreigRequest;
import com.ytjj.qmyx.supplychain.common.model.request.YxFreightTemplate;
import com.ytjj.qmyx.supplychain.service.Impl.FreightTemplateService;
import com.ytjj.qmyx.supplychain.service.ProvincesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/freightTemplate")
public class FreightTemplateController {

    @Autowired
    private FreightTemplateService freightTemplateService;

    @Autowired
    private ProvincesService provincesService;

    /**
     * 模板列表
     * @return
     */
    @PostMapping("/page")
    public CommonResult selectFreightTemplatePage(@RequestBody FreigRequest freigRequest) {
        CommonPage commonPage = freightTemplateService.selectFreightTemplatePage(freigRequest);
        return CommonResult.success(commonPage);
    }

    /**
     * 供应链新建模板
     * @param yxFreightTemplate
     * @return
     */
    @PostMapping("/insertFreightTemplate")
    public CommonResult insertFreightTemplate(@RequestBody YxFreightTemplate yxFreightTemplate) {
        return CommonResult.success(freightTemplateService.insertFreightTemplate(yxFreightTemplate));
    }

    /**
     * 模板详情
     * @return
     */
    @GetMapping("/selectYxFreightTemplate")
    public CommonResult selectFreightTemplateResponse(Integer id) {
        return CommonResult.success(freightTemplateService.selectFreightTemplateResponse(id));
    }

    //根据省份id集
    @GetMapping("/getCitysBypids")
    public CommonResult getCitysBypids(@RequestParam(value="pids",required=false) String pids) {
        return CommonResult.success(provincesService.getCitysBypids(pids));
    }
}
